// app.js
var config = require("./config.js")
App({
  globalData: {
  URL:config.url,
  user:''
},
  onLaunch() {
    // 展示本地存储能力
    const logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)

    // 登录
    wx.login({
      success: res => {
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
      }
    })
  },
  
  wxRequest(method,url,data,callback,errFun){
    return new Promise((resolve,reject) =>{
      wx.request({
        url: url,
        method:method,
        data:data,
        header:{
          'content-type':method == 'GET'?'application/json':'application/x-www-form-urlencoded',
          'Accept':'application/json',
          'token':''
        },
        dataType:'json',
        success:function(res){
          console.log(res)
          //console.log(res);
          callback(res)
        },
        fail:function(err){
          reject(err)
        }
      })
    })
  }
})
